$(document).ready(function(e){
$('.section .head').each(function(i,e){
$(e).clone().addClass('clone').prependTo($(e).closest('.section'));
});
function heads(){
var st = $(window).scrollTop();
var ot = $('.section.active').offset().top;
var oh = $('.section.active').height();
var wh = $(window).height();
if(st > ot){
$('.section.active .head.clone').addClass('active');
if(st > (ot+oh-$('.section.active .head.clone').height())){
var t = (ot+oh-$('.section.active .head.clone').height()) - st;
$('.section.active .head.clone').css('top',t+'px');
}
else {
$('.section.active .head.clone').css('top','0px');
}
}
else {
$('.section.active .head.clone').removeClass('active');
}
}
$(window).scroll(function(){
if($('.section.active').length > 0){
heads();
}
});
$('#dialog').text($(window).width()+'px');
$(window).resize(function(){
$('#dialog').text($(window).width()+'px');
});
$('.slider').each(function(i,e){
var dots = '';
$(e).children('div').each(function(ii,ee){
dots += '
';
});
if(dots.length > 24){
$(e).append('');
}
});
$('.linked').mouseenter(function(e){
e.preventDefault();
var c = $(this).data('name');
$(this).addClass('active').siblings().removeClass('active');
$('.'+c).addClass('active').siblings().removeClass('active');
$($(this).attr('href')).addClass('active').siblings().removeClass('active');
});
$('.linked').click(function(e){
e.preventDefault();
var c = $(this).data('name');
$(this).addClass('active').siblings().removeClass('active');
$('.'+c).addClass('active').siblings().removeClass('active');
$($(this).attr('href')).addClass('active').siblings().removeClass('active');
});
$('.next').click(function(e){
e.preventDefault();
if($($(this).attr('href')).children('.active').removeClass('active').next('.container').addClass('active').length == 0){
$($(this).attr('href')).children('.container').first().addClass('active');
}
var d = $($(this).attr('href')).children('.container.active').attr('id');
if($('a[href="#'+d+'"]').closest('.switch').length > 0){
$('a[href="#'+d+'"]').addClass('active').siblings('a').removeClass('active');
}
$('html, body').animate({
scrollTop: $($(this).attr('href')).offset().top - $('.section.active .head.clone').height()
},800);
});
$('.pie').mouseleave(function(){
$(this).find('.default').addClass('active').siblings().removeClass('active');
});
$('.switch.scroll a').click(function(e){
if($($(this).attr('href')).length > 0){
e.preventDefault();
$('html, body').animate({
scrollTop: $($(this).attr('href')).offset().top - $('.section.active .head.clone').height()
},1000);
}
});
$('.switch:not(.scroll) a').click(function(e){
e.preventDefault();
var href = $(this).attr('href');
$(href).addClass('active').siblings().removeClass('active');
$('a[href="'+href+'"]').each(function(i,e){
if($(e).closest('.switch').length > 0){
$(e).addClass('active').siblings('a').removeClass('active');
}
});
$('html, body').animate({
//scrollTop: $($(this).attr('href')).parent().offset().top - $('.section.active .head.clone').height() - 30
},1000);
});
setInterval(function(){
$('.section.active .slider').each(function(i,e){
if($(e).children('.active').removeClass('active').next('div').addClass('active').length < 1){
$(e).children('div').first().addClass('active');
}
if($(e).find('.dot.active').removeClass('active').next('.dot').addClass('active').length < 1){
$(e).find('.dot').first().addClass('active');
}
});
},6000);
$('.dot').click(function(){
console.log($(this).index());
$(this).closest('.slider').children('div').eq($(this).index()).addClass('active').siblings().removeClass('active');
$(this).addClass('active').siblings().removeClass('active');
});
$('#sec-04 g').mouseenter(function(){
var i = $(this).attr('id').replace('-map','');
$('#'+i).addClass('active').siblings().removeClass('active');
}).mouseleave(function(){
var i = $(this).attr('id').replace('-map','');
$('#'+i).removeClass('active').siblings('.default').addClass('active');
});
$('.section').click(function(){
if(!$(this).hasClass('active')){
/*var sh = $('.section.active').removeClass('active').height();
$(this).addClass('active');
var st = $('#title').height() + (($(this).index()-1) * $('#ruler-sec').height());
//console.log($('#title').height() + ','+(($(this).index()-1) +','+ $('#ruler-sec').height()))+' = '+st;
//$('#ruler span').css('top',st+'px');
$('html, body').animate({
scrollTop: st
},{duration: 2000, easing: "linear" });*/
$('.section.active').removeClass('active');
var t = $(this).addClass('active');
//console.log($('#title').height() + ','+(($(this).index()-1) +','+ $('#ruler-sec').height()))+' = '+st;
//$('#ruler span').css('top',st+'px');
$('html, body').animate({
scrollTop: $(t).offset().top
},799, function(){
$(t).addClass('fixed');
setTimeout(function(){
var st = $('#title').height() + (($(t).index()-1) * $('#ruler-sec').height());
$('html, body').scrollTop(st);
$(t).removeClass('fixed');
$('html, body').scrollTop($(t).offset().top);
},20);
});
}
});
function gradualScroll(e){
}
});
function containerOpen(section, container){
$("#"+section+" .container").removeClass('active');
$("#"+container).addClass('active');
var header = document.getElementsByClassName('section active');
var headerTopPos = header.length > 0 && header[0] ? header[0].offsetTop : 0;
$('html, body').animate({
scrollTop: headerTopPos
},1000);
}